/* Copyright (C) 2008, 2009, 2010 Faindu GmbH, Switzerland.
* All Rights Reserved. The following is Source Code and is subject to all restrictions 
* on such code as contained in the license accompanying this project. */
package blocstac.editimage.crop
{

import blocstac.api.blocbox.MimeType;
import blocstac.editimage.base.ImageModel;
import blocstac.editimage.base.ImageOperation;

import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Rectangle;

import flexunit.framework.TestCase;

public class CropOperationTest extends TestCase
{
	
    //==========================================================================
    //
    //  Test set up and tear down
    //
    //--------------------------------------------------------------------------  
	private var op:ImageOperation
	private var imageModel:ImageModel
	private var mask:Rectangle
	private var imageOffset:Matrix
	private var imageData:BitmapData
	
	override public function setUp(): void
	{
		mask = new Rectangle(0, 3, 5, 7)
		imageOffset = new Matrix()
		op = new CropOperation(mask, imageOffset)
		
		imageData = new BitmapData(9, 13)
		
		imageModel = new ImageModel()
		imageModel.angle = 11
		imageModel.editedScaleX = 23
		imageModel.editedScaleY = 57
		imageModel.mimeType = new MimeType(MimeType.MIMETYPE_PNG)
		imageModel.updateImageData(imageData)
		imageModel.resetImageDataChanged()
	}
	
	override public function tearDown():void
	{
	}
	
    //==========================================================================
    //
    //  Tests
    //
    //--------------------------------------------------------------------------  
	[Test]
	public function test_apply(): void
	{
		op.apply(imageModel)
		
		assertEquals(0, imageModel.angle)
		assertEquals(1, imageModel.editedScaleX)
		assertEquals(1, imageModel.editedScaleY)
		
		var imageData:BitmapData = imageModel.imageData
		assertEquals(5, imageData.width)
		assertEquals(7, imageData.height)
		assertTrue(imageModel.imageDataChanged)
	}

	[Test]
	public function test_undo(): void
	{
		op.apply(imageModel)
		op.undo(imageModel)
		
		assertEquals(11, imageModel.angle)
		assertEquals(23, imageModel.editedScaleX)
		assertEquals(57, imageModel.editedScaleY)
		
		var imageData:BitmapData = imageModel.imageData
		assertEquals(9, imageData.width)
		assertEquals(13, imageData.height)
		assertTrue(imageModel.imageDataChanged)
	}

}
}